home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / GPP257.ZIP / cplusinc / libiop.h < prev    next >
C/C++ Source or Header  |  1993-11-13  |  11KB  |  266 lines

  1. /* 
  2. Copyright (C) 1993 Free Software Foundation
  3.  
  4. This file is part of the GNU IO Library.  This library is free
  5. software; you can redistribute it and/or modify it under the
  6. terms of the GNU General Public License as published by the
  7. Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9.  
  10. This library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. GNU General Public License for more details.
  14.  
  15. You should have received a copy of the GNU General Public License
  16. along with GNU CC; see the file COPYING.  If not, write to
  17. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. As a special exception, if you link this library with files
  20. compiled with a GNU compiler to produce an executable, this does not cause
  21. the resulting executable to be covered by the GNU General Public License.
  22. This exception does not however invalidate any other reasons why
  23. the executable file might be covered by the GNU General Public License. */
  24.  
  25. #include <errno.h>
  26. #ifndef errno
  27. extern int errno;
  28. #endif
  29.  
  30. #include "iolibio.h"
  31.  
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35.  
  36. typedef enum _IO_seekflags_ {
  37.   _IO_seek_set = 0,
  38.   _IO_seek_cur = 1,
  39.   _IO_seek_end = 2,
  40.  
  41.   /* These bits are ignored unless the _IO_FILE has independent
  42.      read and write positions. */
  43.   _IO_seek_not_in = 4,    /* Don't move read posistion. */
  44.   _IO_seek_not_out = 8,    /* Don't move write posistion. */
  45.   _IO_seek_pos_ignored = 16, /* Result is ignored (except EOF) */
  46. } _IO_seekflags;
  47.  
  48. typedef int (*_IO_overflow_t) _PARAMS((_IO_FILE*, int));
  49. typedef int (*_IO_underflow_t) _PARAMS((_IO_FILE*));
  50. typedef _IO_size_t (*_IO_xsputn_t) _PARAMS((_IO_FILE*,const void*,_IO_size_t));
  51. typedef _IO_size_t (*_IO_xsgetn_t) _PARAMS((_IO_FILE*, void*, _IO_size_t));
  52. typedef _IO_ssize_t (*_IO_read_t) _PARAMS((_IO_FILE*, void*, _IO_ssize_t));
  53. typedef _IO_ssize_t (*_IO_write_t) _PARAMS((_IO_FILE*,const void*,_IO_ssize_t));
  54. typedef int (*_IO_stat_t) _PARAMS((_IO_FILE*, void*));
  55. typedef _IO_fpos_t (*_IO_seek_t) _PARAMS((_IO_FILE*, _IO_off_t, int));
  56. typedef int (*_IO_doallocate_t) _PARAMS((_IO_FILE*));
  57. typedef int (*_IO_pbackfail_t) _PARAMS((_IO_FILE*, int));
  58. typedef int (*_IO_setbuf_t) _PARAMS((_IO_FILE*, char *, _IO_ssize_t));
  59. typedef int (*_IO_sync_t) _PARAMS((_IO_FILE*));
  60. typedef void (*_IO_finish_t) _PARAMS((_IO_FILE*)); /* finalize */
  61. typedef int (*_IO_close_t) _PARAMS((_IO_FILE*)); /* finalize */
  62. typedef _IO_fpos_t (*_IO_seekoff_t) _PARAMS((_IO_FILE*, _IO_off_t, _IO_seekflags));
  63.  
  64. /* The _IO_seek_cur and _IO_seek_end options are not allowed. */
  65. typedef _IO_fpos_t (*_IO_seekpos_t) _PARAMS((_IO_FILE*, _IO_fpos_t, _IO_seekflags));
  66.  
  67. struct _IO_jump_t {
  68.     _IO_overflow_t __overflow;
  69.     _IO_underflow_t __underflow;
  70.     _IO_xsputn_t __xsputn;
  71.     _IO_xsgetn_t __xsgetn;
  72.     _IO_read_t __read;
  73.     _IO_write_t __write;
  74.     _IO_doallocate_t __doallocate;
  75.     _IO_pbackfail_t __pbackfail;
  76.     _IO_setbuf_t __setbuf;
  77.     _IO_sync_t __sync;
  78.     _IO_finish_t __finish;
  79.     _IO_close_t __close;
  80.     _IO_stat_t __stat;
  81.     _IO_seek_t __seek;
  82.     _IO_seekoff_t __seekoff;
  83.     _IO_seekpos_t __seekpos;
  84. #if 0
  85.     get_column;
  86.     set_column;
  87. #endif
  88. };
  89.  
  90. /* Generic functions */
  91.  
  92. extern _IO_fpos_t _IO_seekoff _PARAMS((_IO_FILE*, _IO_off_t, _IO_seekflags));
  93. extern _IO_fpos_t _IO_seekpos _PARAMS((_IO_FILE*, _IO_fpos_t, _IO_seekflags));
  94.  
  95. extern int _IO_switch_to_get_mode _PARAMS((_IO_FILE*));
  96. extern void _IO_init _PARAMS((_IO_FILE*, int));
  97. extern int _IO_sputbackc _PARAMS((_IO_FILE*, int));
  98. extern int _IO_sungetc _PARAMS((_IO_FILE*));
  99. extern void _IO_un_link _PARAMS((_IO_FILE*));
  100. extern void _IO_link_in _PARAMS((_IO_FILE *));
  101. extern void _IO_doallocbuf _PARAMS((_IO_FILE*));
  102. extern void _IO_unsave_markers _PARAMS((_IO_FILE*));
  103. extern void _IO_setb _PARAMS((_IO_FILE*, char*, char*, int));
  104. extern unsigned _IO_adjust_column _PARAMS((unsigned, const char *, int));
  105. #define _IO_sputn(__fp, __s, __n) (__fp->_jumps->__xsputn(__fp, __s, __n))
  106.  
  107. /* Marker-related function. */
  108.  
  109. extern void _IO_init_marker _PARAMS((struct _IO_marker *, _IO_FILE *));
  110. extern void _IO_remove_marker _PARAMS((struct _IO_marker*));
  111. extern int _IO_marker_difference _PARAMS((struct _IO_marker *, struct _IO_marker *));
  112. extern int _IO_marker_delta _PARAMS((struct _IO_marker *));
  113. extern int _IO_seekmark _PARAMS((_IO_FILE *, struct _IO_marker *, int));
  114.  
  115. /* Default jumptable functions. */
  116.  
  117. extern int _IO_default_doallocate _PARAMS((_IO_FILE*));
  118. extern void _IO_default_finish _PARAMS((_IO_FILE *));
  119. extern int _IO_default_pbackfail _PARAMS((_IO_FILE*, int));
  120. extern int _IO_default_setbuf _PARAMS((_IO_FILE *, char*, _IO_ssize_t));
  121. extern _IO_size_t _IO_default_xsputn _PARAMS((_IO_FILE *, const void*, _IO_size_t));
  122. extern _IO_size_t _IO_default_xsgetn _PARAMS((_IO_FILE *, void*, _IO_size_t));
  123. extern _IO_fpos_t _IO_default_seekoff _PARAMS((_IO_FILE*, _IO_off_t, _IO_seekflags));
  124. extern _IO_fpos_t _IO_default_seekpos _PARAMS((_IO_FILE*, _IO_fpos_t, _IO_seekflags));
  125. extern _IO_ssize_t _IO_default_write _PARAMS((_IO_FILE*,const void*,_IO_ssize_t));
  126. extern _IO_ssize_t _IO_default_read _PARAMS((_IO_FILE*, void*, _IO_ssize_t));
  127. extern int _IO_default_stat _PARAMS((_IO_FILE*, void*));
  128. extern _IO_fpos_t _IO_default_seek _PARAMS((_IO_FILE*, _IO_off_t, int));
  129. #define _IO_default_sync (_IO_sync_t)0
  130. #define _IO_default_close (_IO_close_t)0
  131.  
  132. extern struct _IO_jump_t _IO_file_jumps;
  133. extern struct _IO_jump_t _IO_proc_jumps;
  134. extern struct _IO_jump_t _IO_str_jumps;
  135. extern int _IO_do_write _PARAMS((_IO_FILE*, const char*, _IO_size_t));
  136. extern int _IO_flush_all _PARAMS(());
  137. extern void _IO_flush_all_linebuffered _PARAMS(());
  138.  
  139. #define _IO_do_flush(_f) _IO_do_write(_f, _f->_pbase, _f->_pptr-_f->_pbase)
  140. #define _IO_in_put_mode(_fp) ((_fp)->_flags & _IO_CURRENTLY_PUTTING)
  141. #define _IO_mask_flags(fp, f, mask) \
  142.        ((fp)->_flags = ((fp)->_flags & ~(mask)) | ((f) & (mask)))
  143. #define _IO_setg(fp, eb, g, eg) \
  144.        ((fp)->_eback = (eb), (fp)->_gptr = (g), (fp)->_egptr = (eg))
  145. #define _IO_setp(__fp, __p, __ep) \
  146.        ((__fp)->_pbase = (__fp)->_pptr = __p, (__fp)->_epptr = (__ep))
  147. #define _IO_have_backup(fp) ((fp)->_other_gbase != NULL)
  148. #define _IO_in_backup(fp) ((fp)->_flags & _IO_IN_BACKUP)
  149. #define _IO_have_markers(fp) ((fp)->_markers != NULL)
  150. #define _IO_blen(p) ((fp)->_IO_buf_end - (fp)->_IO_buf_base)
  151.  
  152. /* Jumptable functions for files. */
  153.  
  154. extern int _IO_file_doallocate _PARAMS((_IO_FILE*));
  155. int _IO_file_setbuf _PARAMS((_IO_FILE *, char*, _IO_ssize_t));
  156. extern _IO_fpos_t _IO_file_seekoff _PARAMS((_IO_FILE*, _IO_off_t, _IO_seekflags));
  157. extern _IO_size_t _IO_file_xsputn _PARAMS((_IO_FILE*,const void*,_IO_size_t));
  158. extern int _IO_file_stat _PARAMS((_IO_FILE*, void*));
  159. extern int _IO_file_close _PARAMS((_IO_FILE*));
  160. extern int _IO_file_underflow _PARAMS((_IO_FILE *));
  161. extern int _IO_file_overflow _PARAMS((_IO_FILE *, int));
  162. #define _IO_file_is_open(__fp) ((__fp)->_fileno >= 0)
  163. extern void _IO_file_init _PARAMS((_IO_FILE*));
  164. extern _IO_FILE* _IO_file_attach _PARAMS((_IO_FILE*, int));
  165. extern _IO_FILE* _IO_file_fopen _PARAMS((_IO_FILE*, const char*, const char*));
  166. extern _IO_ssize_t _IO_file_write _PARAMS((_IO_FILE*,const void*,_IO_ssize_t));
  167. extern _IO_ssize_t _IO_file_read _PARAMS((_IO_FILE*, void*, _IO_ssize_t));
  168. extern int _IO_file_sync _PARAMS((_IO_FILE*));
  169. extern int _IO_file_close_it _PARAMS((_IO_FILE*));
  170. extern _IO_fpos_t _IO_file_seek _PARAMS((_IO_FILE *, _IO_off_t, int));
  171. extern void _IO_file_finish _PARAMS((_IO_FILE*));
  172.  
  173. /* Other file functions. */
  174. extern _IO_FILE* _IO_file_attach _PARAMS((_IO_FILE *, int));
  175.  
  176. /* Jumptable functions for proc_files. */
  177. extern _IO_FILE* _IO_proc_open _PARAMS((_IO_FILE*, const char*, const char *));
  178. extern int _IO_proc_close _PARAMS((_IO_FILE*));
  179.  
  180. /* Jumptable functions for strfiles. */
  181. extern int _IO_str_underflow _PARAMS((_IO_FILE*));
  182. extern int _IO_str_overflow _PARAMS((_IO_FILE *, int));
  183. extern int _IO_str_pbackfail _PARAMS((_IO_FILE*, int));
  184. extern _IO_fpos_t _IO_str_seekoff _PARAMS((_IO_FILE*,_IO_off_t,_IO_seekflags));
  185.  
  186. /* Other strfile functions */
  187. extern void _IO_str_init_static _PARAMS((_IO_FILE *, char*, int, char*));
  188. extern void _IO_str_init_readonly _PARAMS((_IO_FILE *, const char*, int));
  189. extern _IO_ssize_t _IO_str_count _PARAMS ((_IO_FILE*));
  190.  
  191. extern _IO_size_t _IO_getline _PARAMS((_IO_FILE*,char*,_IO_size_t,char,int));
  192. extern double _IO_strtod _PARAMS((const char *, char **));
  193. extern char * _IO_dtoa _PARAMS((double __d, int __mode, int __ndigits,
  194.                 int *__decpt, int *__sign, char **__rve));
  195. extern int _IO_outfloat _PARAMS((double __value, _IO_FILE *__sb, int __type,
  196.                  int __width, int __precision, int __flags,
  197.                  int __sign_mode, int __fill));
  198.  
  199. extern _IO_FILE *_IO_list_all;
  200. extern void (*_IO_cleanup_registration_needed)();
  201.  
  202. #ifndef EOF
  203. #define EOF (-1)
  204. #endif
  205. #ifndef NULL
  206. #if !defined(__cplusplus) || defined(__GNUC__)
  207. #define NULL ((void*)0)
  208. #else
  209. #define NULL (0)
  210. #endif
  211. #endif
  212.  
  213. #define FREE_BUF(_B) free(_B)
  214. #define ALLOC_BUF(_S) (char*)malloc(_S)
  215.  
  216. #ifndef OS_FSTAT
  217. #define OS_FSTAT fstat
  218. #endif
  219. struct stat;
  220. extern _IO_ssize_t _IO_read _PARAMS((int, void*, _IO_size_t));
  221. extern _IO_ssize_t _IO_write _PARAMS((int, const void*, _IO_size_t));
  222. extern _IO_off_t _IO_lseek _PARAMS((int, _IO_off_t, int));
  223. extern int _IO_close _PARAMS((int));
  224. extern int _IO_fstat _PARAMS((int, struct stat *));
  225.  
  226. /* Operations on _IO_fpos_t.
  227.    Normally, these are trivial, but we provide hooks for configurations
  228.    where an _IO_fpos_t is a struct.
  229.    Note that _IO_off_t must be an integral type. */
  230.  
  231. /* _IO_pos_BAD is an _IO_fpos_t value indicating error, unknown, or EOF. */
  232. #ifndef _IO_pos_BAD
  233. #define _IO_pos_BAD ((_IO_fpos_t)(-1))
  234. #endif
  235. /* _IO_pos_as_off converts an _IO_fpos_t value to an _IO_off_t value. */
  236. #ifndef _IO_pos_as_off
  237. #define _IO_pos_as_off(__pos) ((_IO_off_t)(__pos))
  238. #endif
  239. /* _IO_pos_adjust adjust an _IO_fpos_t by some number of bytes. */
  240. #ifndef _IO_pos_adjust
  241. #define _IO_pos_adjust(__pos, __delta) ((__pos) += (__delta))
  242. #endif
  243. /* _IO_pos_0 is an _IO_fpos_t value indicating beginning of file. */
  244. #ifndef _IO_pos_0
  245. #define _IO_pos_0 ((_IO_fpos_t)0)
  246. #endif
  247.  
  248. #ifdef __cplusplus
  249. }
  250. #endif
  251.  
  252. #if defined(__STDC__) || defined(__cplusplus)
  253. #define _IO_va_start(args, last) va_start(args, last)
  254. #else
  255. #define _IO_va_start(args, last) va_start(args)
  256. #endif
  257.  
  258. #if 1
  259. #define COERCE_FILE(FILE) /* Nothing */
  260. #else
  261. /* This is part of the kludge for binary compatibility with old stdio. */
  262. #define COERCE_FILE(FILE) \
  263.   (((FILE)->_IO_file_flags & _IO_MAGIC_MASK) == _OLD_MAGIC_MASK \
  264.     && (FILE) = *(FILE**)&((int*)fp)[1])
  265. #endif
  266.